<?php
/*
	template.php
*/

if (!defined('IN_ROACH')) { exit; } // we don't want direct access to this file

class template
{
	private $path;
	
	private $html;
	private $vars = array();
	
	// get template path
	function __construct($templatePath)
	{
		$this->path = $templatePath;
	}
	
	// load template from file
	public function assign_file($filename)
	{
		$this->html = file_get_contents($this->path.DS.'html'.DS.$filename);
	}
	
	// load template variables
	public function assign_vars($templateVars)
	{
		$this->vars = array_merge($this->vars, $templateVars);
	}
	
	// parse template data and print the results
	public function parse()
	{
		// wrap the template HTML between the header and footer
		$this->html = file_get_contents($this->path.DS.'html'.DS.'header.html').$this->html.file_get_contents($this->path.DS.'html'.DS.'footer.html');
		
		foreach($this->vars as $key => $value)
		{
			$this->html = preg_replace('#{'.$key.'}#', $value, $this->html);
		}
		
		echo $this->html;
	}
}

?>